package com.hgy.carsb.controller;

import com.hgy.carsb.entity.UnitAnalysisDetail;
import com.hgy.carsb.service.UnitAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller

public class UnitAnalysisController {

    @Autowired
    private UnitAnalysisService unitAnalysisService;

    private int year = 2020;
    private int month = 4;

    @PostMapping("/unit")
    @ResponseBody
    public List<UnitAnalysisDetail> getDetail(@RequestParam("index")String command){
        List<UnitAnalysisDetail> ans = new ArrayList<>();
        String code1 = "";
        String code2 = "";
        switch (command){
            case "0":
                code1 = "interest";
                code2 = "income";
                break;
            case "1":
                code1 = "dept";
                code2 = "asset";
                break;
            case "2":
                code1 = "asset";
                code2 = "income";
                break;
        }
        String[] company = {"FAWVOLKSWAGEN", "FAWKC", "FAWJF", "FAWCARCO", "FAWXL", "FAWMC"};
        for (int i=0; i<6; i++){
            ans.add(unitAnalysisService.getUnitDetail(year, month, code1, code2, company[i]));
        }
        return ans;
    }
}
